﻿using Commons.Responses;
using DomainCommons.Models;
using IApplicationServices.Helpers;
using IRepositories;
using ORM;
using System.Linq.Expressions;

namespace IApplicationServices
{
    public interface IBaseApplicationService<T,TEntity,TApiEntity> where TEntity : class, IEntity<T>, new ()
       where TApiEntity : class, IEntity<T>, new ()
    {
        PSPDbContext Context { get; }
        IBaseRepository<T, TEntity> Repository { get; }

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="apiBo"></param>
        /// <param name="expressions"></param>
        /// <returns></returns>
        Task<MessageResponse> AddAsync(TApiEntity apiBo);
        Task<MessageResponse> AddTOtherAsync<Tid, TOther, TApiOther>(TApiOther request) where TOther : class, IEntity<Tid>, new() where TApiOther : class, IEntity<Tid>, new();
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="apiBo"></param>
        /// <param name="expressions"></param>
        /// <returns></returns>
        Task<MessageResponse> UpdateAsync(TApiEntity apiBo);
        Task<MessageResponse> UpdateOtherAsync<Tid, TOther, TApiOther>(TApiOther request) where TOther : class, IEntity<Tid>, new() where TApiOther : class, IEntity<Tid>, new();
        /// <summary>
        /// 根据id获取一条数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<DataResponse<TApiEntity>> GetByIdAsync(T id);
        /// <summary>
        /// 根据条件获取一条数据
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        Task<DataResponse<TApiEntity>> GetAsync(Expression<Func<TEntity, bool>> predicate);
        Task<DataResponse<TApiOther>> GetOtherAsync<Tid,TOther,TApiOther>(Expression<Func<TOther, bool>> predicate) where TOther : class, IEntity<Tid>, new() where TApiOther : class, IEntity<Tid>, new();
        /// <summary>
        /// 根据条件获取一组数据
        /// </summary>
        /// <param name="predicate"></param>
        /// <returns></returns>
        Task<DatasResponse<TApiEntity>> GetAllAsync(Expression<Func<TEntity, bool>> predicate);
        /// <summary>
        /// 获取一组数据
        /// </summary>
        /// <returns></returns>
        Task<DatasResponse<TApiEntity>> GetAllAsync();
        /// <summary>
        /// 根据id查找是否存在
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<bool> HasAsync(T id);
        /// <summary>
        /// 根据查询条件获取一组数据
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="predicate"></param>
        /// <returns></returns>
        Task<DatasResponse<TApiEntity>> GetBySelectAsync(int pageIndex, int pageSize, Expression<Func<TEntity, bool>> predicate);
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<MessageResponse> DeleteByIdAsync(T id);
        /// <summary>
        /// 软删除
        /// </summary>
        /// <param name="id"></param>
        /// <param name="expressions"></param>
        /// <returns></returns>
        Task<MessageResponse> SoftDeleteByIdAsync(T id);
        /// <summary>
        /// 批量软删除
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="expressions"></param>
        /// <returns></returns>
        Task<MessageResponse> SoftDeleteRangeByIdAsync(List<T> ids);
    }
}
